//package com.tuzhi.base.web.interceptor;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.tuzhi.common.domain.ResultBO;
//import com.tuzhi.common.helper.ResultHelper;
//import com.tuzhi.util.RSAUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//@Component
//public class AuthInterceptor implements HandlerInterceptor {
//    Logger logger = LoggerFactory.getLogger(AuthInterceptor.class);
//    @Value("${security.gatewayHeader:tz-gateway-header}")
//    private String gatewayHeader = "tz-gateway-header";//GATEWAY_TOKEN_HEADER
//
//    @Value("${security.gatewayFlag:tz-gateway-ok}")
//    private String gatewayFlag = "tz-gateway-ok";//GATEWAY_TOKEN_HEADER
//    static ObjectMapper mapper = new ObjectMapper();
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        logger.info("gatewayHeader={}", gatewayHeader);
//        logger.info("gatewayFlag={}", gatewayFlag);
//        String gatewayHeaderValue = request.getHeader(gatewayHeader);
//        if (gatewayHeaderValue == null) {
//            ResultBO resultBO = ResultHelper.error("404，错误的路径！");
//            response.setContentType("application/json");
//            response.getWriter().write(mapper.writeValueAsString(resultBO));
//            return false;
//        }
//        boolean sign = RSAUtil.verify(gatewayFlag.getBytes(), gatewayHeaderValue, RSAConfig.PUBLIC_KEY);
//        if (!sign) {
//            ResultBO resultBO = ResultHelper.error("404，错误的路径！");
//            response.setContentType("application/json");
//            response.getWriter().write(mapper.writeValueAsString(resultBO));
//            return false;
//        }
//        return true;
//    }
//}